import { request } from "@/utils";

/**
 * 获取表格详情——列表页
 * @param {string} id 表格id
 * @returns {Promise<ApiRet>}
 */
const getExcelDetail = (id) => {
    return request({
        url: `/excel/get/${id}`,
        method: 'GET'
    })
}
/**
 * 获取侧边栏表格信息和表格详情页-弃用
 * @returns {Promise<ApiRet>}
 */
const getExcelList = () => {
    return request({
        url: '/excel/title',
        method: 'GET'
    })
}
/**
 * 根据用户id获取表格目录列表
 * @returns {Promise<ApiRet>}
 */
const getExcelContentsByUserId = (userId) => {
    return request({
        url: `/excel/getExcelContents/${userId}`,
        method: 'GET'
    })
}
/**
 * 删除表格——列表页
 * @param {string} id 表格id
 * @returns {Promise<ApiRet>}
 */
const delExcel = (id) => {
    return request({
        url: `/excel/delete/${id}`,
        method: 'DELETE'
    })
}
/**
 * 更新表格——详情页
 * 新建表格——列表页
 * @param {string} id 表格id
 * @param {string} title 表格标题
 * @param {string} url 表格url
 * @returns {Promise<ApiRet>}
 */
const updateExcel = (data) => {
    return request({
        url: '/excel/update',
        method: 'PUT',
        data
    })
}

/**
 * 已经废弃
 * 添加表格——列表页
 * @param {string} folderId 文件夹id
 * @param {string} title 表格标题
 * @param {string} url 表格url
 * @returns {Promise<ApiRet>}
 */
const addExcel = ({ folderId, title, url }) => {
    return request({
        url: '/excel/upload',
        method: 'POST',
        data: {
            folderId,
            title,
            url
        }
    })
}

/**
 * 搜索表格——列表页
 * @param {string} title 表格标题
 * @returns {Promise<ApiRet>}
 */
const searchExcel = (title) => {
    return request({
        url: '/excel/search',
        method: 'GET',
        params: { title }
    })
}

/**
 * 分页查询——列表页
 * @param {integer} current 当前页
 * @param {integer} size 每页条数
 * @returns {Promise<ApiRet>}
 */
const getExcelListByPage = (data={}, params={}) => {
    return request({
        url: '/excel/page',
        method: 'POST',
        data,
        params
    })
}

export {
    getExcelDetail,
    delExcel,
    updateExcel,
    addExcel,
    getExcelList,
    searchExcel,
    getExcelContentsByUserId,
    getExcelListByPage
}